/***************************************************************************
 *   Copyright (C) 2008 Ivan Topolsky   *
 *   ivan.topolsky@genebio.com   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU Library General Public License as       *
 *   published by the Free Software Foundation; either version 2 of the    *
 *   License, or (at your option) any later version.                       *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU Library General Public     *
 *   License along with this program; if not, write to the                 *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#ifndef BOLPEAKINTENSITYRM_H
#define BOLPEAKINTENSITYRM_H

#ifdef HAVE_BOOST_SERIALIZATION
#include <boost/serialization/nvp.hpp>
#include <boost/serialization/base_object.hpp>
#include <boost/serialization/export.hpp>
#endif

#ifdef HAVE_PROTOBUF
#ifdef _MSC_VER
// we don't create DLLs and thus don't need to pay attention to this warning
#pragma warning( disable: 4251 )
#endif
#include "runlcmsms.pb.h"
#endif

#include "peakintensity.h"

namespace bol {

/**
Variation of Peak Intensity used to store ?RM peaks 
(either Single Reaction Monitoring SRM
or Multiple Reaction Monitoring MRM)

This class store another m/z :
the m/z Selective Product Ion which results after the Mass Transition

	@author Alexandre Masselot,GeneBio,http://www.genebio.com, <alexandre.masselot@gmail.com>
*/
  class PeakIntensityRM : public PeakIntensity {
    private:
      const double m_selectiveProductIon;
    public:
      PeakIntensityRM(const double m1, const Pchargemask charges=0, const double i=0) : PeakIntensity(m1,charges,i), m_selectiveProductIon(0.) {}
      PeakIntensityRM(const double m1, const double m2, const Pchargemask charges=0, const double i=0) : PeakIntensity(m1,charges,i), m_selectiveProductIon(m2) {}
      ~PeakIntensityRM() {}

#ifdef HAVE_BOOST_SERIALIZATION
      // *** BOOST serialisation code ***
      friend class boost::serialization::access; // gives access to serialisator
      template<class Archive> void serialize ( Archive & ar, const unsigned int version ) const
      {
        // base class serialisation - warning, as there are several variable, the order is critical...
        // ... well not for XML. But for most other archive types.
        ar & boost::serialization::make_nvp("PeakIntensity", boost::serialization::base_object<PeakIntensity> ( *this ));

        ar & boost::serialization::make_nvp("selectiveProductIon", m_selectiveProductIon);
        // Rank is a computed value so we don't save it.
      }
#endif

      const double selectiveProductIon() { return m_selectiveProductIon; } ;
  };

#ifdef HAVE_PROTOBUF
  static inline bool operator<< (protobuf::RunLcmsms::Spectrum::Peak& pb, const class PeakIntensityRM& p) {
    pb.set_selectiveProductIon(p.selectiveProductIon());
    pb << static_cast< class PeakIntensity > (p);
    return true;
  }

  static inline bool operator>> (const protobuf::RunLcmsms::Spectrum::Peak& pb, class PeakIntensityRM& p) {
    // intensity is set by constructor when peak is allocated
    (pb) >> (static_cast< class PeakIntensity &> (p));
    return true;
  }
#endif

}

#ifdef HAVE_BOOST_SERIALIZATION
#if defined(WIN32) && (BOOST_VERSION < 103600)
// other wise Visual Studio spits error messages
#include <boost/serialization/extended_type_info_typeid.hpp>
#endif
BOOST_CLASS_EXPORT_GUID(bol::PeakIntensityRM, "PeakIntensityRM") // register GUID
#endif

#endif
